{extend name="admin/base" /}
{block name="main"}
<!--添加按钮和搜索框-->
<div class="mb-20 flex flex-pack-justify">
    <div class="">
        <a href="{:__URL('ADMIN_MAIN/auth/adduser')}" class="btn btn-primary J-add"><i class="icon icon-add1"></i> 添加子账号</a>
    </div>
    <div class="input-group search-input-group">
        <input type="text" class="form-control" id="search_text" name="search_text" placeholder="请输入账号">
        <span class="input-group-btn "><a class="btn btn-primary search_to">搜索</a></span>
    </div>
</div>
<!--表格-->
<table class="table v-table">
    <thead>
        <tr>
            <th>账号</th>
            <th>使用人</th>
            <th>角色</th>
            <th>状态</th>
            <th class="col-md-2 pr-14 operationLeft">操作</th>
        </tr>
    </thead>
    <tbody class="trs" id="list">
        
    </tbody>
</table>
<div class="page clearfix">
    <div class="M-box3 m-style fr">
    </div>
</div>

<!-- page end -->
{/block}
{block name="script"}
<script type="text/javascript">
  require(['utilAdmin'], function (utilAdmin) {
      utilAdmin.tips();
    $(function(){
        LoadingInfo(1);
    });
function LoadingInfo(page_index) {
    $('#page_index').val(page_index ? page_index : '1');
	var search_text = $("#search_text").val();
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/auth/userlist')}",
		data : { "page_index" : page_index, "page_size" : $("#showNumber").val(), "search_text" : search_text },
		success : function(data) {
			var html = '';
			if (data["data"].length > 0) {
				for (var i = 0; i < data["data"].length; i++) {
					html += '<tr>';
					html += '<td>' + data["data"][i]["user_tel"] + '</td>';
					html += '<td>' + data["data"][i]["user"] + '</td>';
					html += data["data"][i]["group_name"] ? '<td>' + data["data"][i]["group_name"] + '</td>' : '<td class="center"></td>';
					html += data["data"][i]["user_status"] == 0 ? '<td><span class="label label-danger">停用</span></td>' : '<td><span class="label label-success">正常</span></td>';
					if(data['data'][i]['is_admin'] > 0){
						html += '<td class="operationLeft" style="color:#B5B3B3;">超级管理员不可操作</td>';
					}else{
						html += '<td class="fs-0 operationLeft"><a class="btn-operation" href="'+__URL('ADMIN_MAIN/auth/edituser?uid=' + data["data"][i]["uid"])+'">编辑</a>';
						html += data["data"][i]["user_status"] == 0 ? '<a class="btn-operation unLock" href="javascript:void(0);" data-unlockId="'+data["data"][i]["uid"]+'">启用</a> ' : '<a class="btn-operation Lock" href="javascript:void(0);" data-lockId="'+data["data"][i]["uid"]+'">停用</a>';
						html += '<a class="btn-operation reset" href="javascript:void(0);" data-id="' + data["data"][i]["uid"] + '">重置密码</a>';
						html += '<a href="javascript:void(0);" data-delId="' + data["data"][i]["uid"] + '" class="btn-operation text-red1 del">删除</a></td>';
					}
					html += '</tr>';
				}
			} else {
				html += '<tr align="center"><td colspan="5" class="h-200">暂无符合条件的数据记录</td></tr>';
			}
			$("#list").html(html);
            utilAdmin.tips();
			utilAdmin.page(".M-box3", data['total_count'], data["page_count"], page_index, LoadingInfo);
		}
	});
}

function resetPassword(uid){
    utilAdmin.alert('你确定重置密码：123456？',function(){
        $.ajax({
            type: "post",
            url: "{:__URL('ADMIN_MAIN/auth/resetuserpassword')}",
            async: true,
            data: {
                "uid": uid
            },
            success: function (data) {
                if (data["code"] > 0) {
                    utilAdmin.message("操作成功！", "success",LoadingInfo($('#page_index').val()));
                } else {
                    utilAdmin.message(data['message'],'danger');
                    return false;
                }
            }
        });
    })
}

function lock(uid){
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/auth/userlock')}",
		data : { "uid" : uid },
		success : function(data) {
			if(data["code"] > 0 ){
                            utilAdmin.message(data["message"],'success',LoadingInfo($('#page_index').val()));
			}else{
                            utilAdmin.message(data["message"],'danger');
			}
		}
	});
}

function unlock(uid){
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/Auth/userunlock')}",
		data : { "uid" : uid },
		success : function(data) {
			if(data["code"] > 0 ){
                            utilAdmin.message(data["message"],'success',LoadingInfo($('#page_index').val()));
			}else{
                            utilAdmin.message(data["message"],'danger');
			}
		}
	});
}

function delectAdminUser(uid){
    utilAdmin.alert('确定要删除该用户吗？',function(){
        $.ajax({
                url : "{:__URL('ADMIN_MAIN/auth/deleteadminuserajax')}",
                data : {"uid" : uid },
                type : "post",
                dataType : "json",
                success : function(data) {
                        if(data['code'] > 0){
                            utilAdmin.message(data["message"],'success',LoadingInfo($('#page_index').val()));
                        }else{
                            utilAdmin.message(data["message"],'danger');
                        }
                }
        });
    })
}

//全选
function CheckAll(event){
	var checked = event.checked;
	$("#list input[type = 'checkbox']").prop("checked",checked);
}

    $("body").on("click",".search_to",function(){
        LoadingInfo(1);
    })
    $("body").on("click",".unLock",function(){
        var uid=$(this).attr("data-unlockId");
        // $(this).remove();
        $(".tooltip.fade.top.in").remove();
        unlock(uid);
    })
    $("body").on("click",".Lock",function(){
        var uid=$(this).attr("data-lockId");
        // $(this).remove();
        $(".tooltip.fade.top.in").remove();
        lock(uid);
    })
    $("body").on("click",".del",function(){
        var uid=$(this).attr("data-delId");
        delectAdminUser(uid);
    })
    $("body").on("click",".reset",function(){
        var uid=$(this).attr("data-id");
        resetPassword(uid);
    })


  })
</script>
{/block}